package com.ktjiaoyu.crm.controller;

import com.ktjiaoyu.crm.pojo.User;
import com.ktjiaoyu.crm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.jws.WebParam;
import java.util.List;
import java.util.Map;

@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping(value = "/sys/users")
    public String getUsers(Model model){
        List<User> userList = userService.findAllUsers();
        model.addAttribute("users",userList);
        return "demo/list";
    }

    @GetMapping(value = "/user/{id}")
    public String getUser(@PathVariable("id")Long usrId, Map map){
        User user = userService.getUser(usrId);
        map.put("user",user);
        /*model.addAttribute("user",user);*/
        return "demo/hello";
    }

    /*@RequestMapping(value = "/user",method = RequestMethod.GET)
    public User getUser(Long usrId){
        User user = userService.getUser(usrId);
        return user;
    }*/

    @RequestMapping(value = "/user/list")
    public String list(Model model){
        List<User> usersAndRole = userService.getUsersAndRole();
        model.addAttribute("userList",usersAndRole);
        return "user/list";
    }

}
